package cn.kgc.tangcco.controller;

import cn.kgc.tangcco.pojo.Idiom;
import cn.kgc.tangcco.pojo.Paginator;
import cn.kgc.tangcco.service.IdiomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 李昊哲
 * @Description
 * @create 2021/1/27 11:59
 */
@RestController
@RequestMapping(value = "/idiom")
public class IdiomController {
    @Autowired
    private IdiomService idiomService;

    @GetMapping(value = "/count")
    public long count() {
        return idiomService.count();
    }

    @GetMapping(value = "/findById/{id}")
    public Idiom findById(@PathVariable("id") Integer id) {
        return idiomService.findById(id);
    }

    @GetMapping(value = "/findAllWithGetForm")
    public String findAllWithGetForm(
            @RequestParam(name = "page", defaultValue = "1", required = true) Integer page,
            @RequestParam(name = "size", defaultValue = "2", required = true) Integer size) {
        return idiomService.findAllWithGetForm(page, size);
    }

    @PostMapping(value = "/findAllWithPostForm")
    public String findAllWithPostForm(
            @RequestParam(name = "page", defaultValue = "1", required = true) Integer page,
            @RequestParam(name = "size", defaultValue = "2", required = true) Integer size) {
        return idiomService.findAllWithPostForm(page, size);
    }

    @PostMapping(value = "/findAllWithPostJson")
    public String findAllWithPostJson(@RequestBody Paginator paginator) {
        return idiomService.findAllWithPostJson(paginator);
    }

    @PutMapping(value = "/save")
    public Idiom save(Idiom idiom) {
        return idiomService.save(idiom);
    }

    @DeleteMapping(value = "/deleteById/{id}")
    public Long deleteById(@PathVariable("id") Integer id) {
        return idiomService.deleteById(id);
    }
}
